package com.jd.org.service.impl;

import com.jd.basic.PageList;
import com.jd.org.domain.Department;
import com.jd.org.mapper.DepartmentMapper;
import com.jd.org.query.DepartmentQuery;
import com.jd.org.service.IDepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class DepartmentServiceImpl implements IDepartmentService {
    @Autowired
    private DepartmentMapper departmentMapper;//乱报错 选第一个的第三个
    @Override
    public List<Department> findAll() {

        return departmentMapper.findAll();
    }

    @Override
    public Department findOne(Long id) {
        return departmentMapper.findOne(id);
    }

    @Override
    public void add(Department department) {
        departmentMapper.add(department);
    }

    @Override
    public void dalete(Long id) {
        departmentMapper.dalete(id);
    }

    @Override
    public void update(Department department) {
        departmentMapper.update(department);
    }

    @Override
    public PageList<Department> queryPage(DepartmentQuery departmentQuery) {
        //查询总条数
        Long count = departmentMapper.queryCount();
        //查询分页数据
        List<Department> rows = departmentMapper.queryData(departmentQuery);
        //封装成pageList
        return new PageList<>(count,rows);
    }


}
